package Tree;

public class Stack {
	Stack hd;
	Stack tl;
	Stack topOfStack;
	
	Stack ()
	{
		hd = null; 
		tl = null;
		topOfStack = null;
	}
	
	public Stack top () 
	{	
		if (topOfStack == null) 
		{
			System.out.println("Error: top(null)");
			System.exit(1);
		}
		else return topOfStack.hd;
		return topOfStack.hd;
	}
	
	public Stack push (Stack x)
	{	
		Stack p;

		p = topOfStack;
		topOfStack = new Stack(); 
		if ( topOfStack != null)	
		{ 	
			topOfStack.hd = new Stack();
			topOfStack.hd = x;
			topOfStack.tl = p;
		}
		else 
		{
			System.out.println("Memory not enough");
			System.exit(1);
		}
		return x;
	}

	public boolean isNull()
	{	
		return (topOfStack == null) ;
	}
}
